/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package co.infinum.goldfinger;

import co.infinum.goldfinger.crypto.ResourceTable;
import ohos.app.Context;
import ohos.biometrics.authentication.BiometricAuthentication;

/**
 * 人脸认证返回码
 *
 * @since 2021-04-12
 */
public class FaceAuthResult {
    /**
     * 认证成功
     */
    public static final int AUTH_SUCCESS = 0;
    /**
     * 认证失败
     */
    public static final int AUTH_FAIL = 1;
    /**
     * 取消认证
     */
    public static final int AUTH_CANCLE = 2;
    /**
     * 认证超时
     */
    public static final int AUTH_TIME_OUT = 3;
    /**
     * 打开相机失败
     */
    public static final int AUTH_OPEN_CAMERA_FAIL = 4;
    /**
     * busy，可能上一个认证没有结束
     */
    public static final int AUTH_BUSY = 5;
    /**
     * 入参错误
     */
    public static final int AUTH_PARAM_ERROR = 6;
    /**
     * 人脸认证锁定（达到错误认证次数了)
     */
    public static final int AUTH_FACE_LOCKED = 7;
    /**
     * 没有录入人脸
     */
    public static final int AUTH_NO_FACE = 8;
    /**
     * 不支持2D人脸识别。
     */
    public static final int AUTH_2D_NOT_SUPPORTED = 9;
    /**
     * 安全级别不支持
     */
    public static final int AUTH_SAFE_LEVEL_NOT_SUPPORTED = 10;
    /**
     * 不是本地认证
     */
    public static final int AUTH_NOT_LOCAL = 11;
    /**
     * 其他问题
     */
    public static final int ERROR_UNKNOWN = 100;
    public static final int NO_HARDWARE = 101;

    private FaceAuthResult() {
        super();
    }

    public static String retAuthenticationTips(Context context, int index) {
        switch (index) {
            case BiometricAuthentication.BA_FAILED:
                return getString(context, ResourceTable.String_BA_FAILED);
            case BiometricAuthentication.BA_CHECK_SUPPORTED:
                return getString(context, ResourceTable.String_BA_CHECK_SUPPORTED);
            case BiometricAuthentication.BA_CHECK_AUTH_TYPE_NOT_SUPPORT:
                return getString(context, ResourceTable.String_BA_CHECK_DISTRIBUTED_AUTH_NOT_SUPPORT);
            case BiometricAuthentication.BA_CHECK_SECURE_LEVEL_NOT_SUPPORT:
                return getString(context, ResourceTable.String_BA_CHECK_SECURE_LEVEL_NOT_SUPPORT);
            case BiometricAuthentication.BA_CHECK_DISTRIBUTED_AUTH_NOT_SUPPORT:
                return getString(context, ResourceTable.String_BA_CHECK_DISTRIBUTED_AUTH_NOT_SUPPORT);
            case BiometricAuthentication.BA_CHECK_NOT_ENROLLED:
                return getString(context, ResourceTable.String_BA_CHECK_NOT_ENROLLED);
            case BiometricAuthentication.BA_CHECK_UNAVAILABLE:
                return getString(context, ResourceTable.String_BA_CHECK_UNAVAILABLE);
            case ERROR_UNKNOWN:
                return getString(context, ResourceTable.String_ERROR_UNKNOWN);
        }
        return "status error" + index;
    }

    public static String getString(Context context, int resid) {
        String str = "id异常";
        try {
            str = context.getResourceManager().getElement(resid).getString();
        } catch (Exception e) {
            return str;
        }
        return str;
    }
}
